import pandas as pd
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
#创建字典
dict = {'语文':[110,95,98,112],'数学':[120,110,80,106],'英语':[105,108,100,97]}
df1 = pd.DataFrame(dict,index)
print('使用字典创建的DataFrame对象df1:\n',df1)
#创建Series对象
s1 = pd.Series([110,120,105],columns)
s2 = pd.Series([95,110,108],columns)
s3 = pd.Series([98,80,100],columns)
s4 = pd.Series([112,106,97],columns)
df2 = pd.DataFrame([s1,s2,s3,s4],index)
print('使用Series对象创建的DataFrame对象df2:\n',df2)
#标准
import pandas as pd
list = [[110,120,105],[95,110,108],[98,80,100],[112,106,97]]
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
df = pd.DataFrame(list,index,columns)
# 表2-4
print('原始数据:\n',df)
print('原始数据:\n',df1.values)
print('原始数据:\n',df1.dtypes)
print('原始数据:\n',df1.index)
print('原始数据:\n',df1.columns)
print('原始数据:\n',df1.T)
print('原始数据:\n',df1.head(),df1.head(3))
print('原始数据:\n',df1.tail(),df1.tail(3))
print('原始数据:\n',df1.shape)
print('原始数据:\n',df1.info)
# 例2-13
import pandas as pd
list = [[110,120,105],[95,110,108],[98,80,100],[112,106,97]]
index = ['王蒙','李珊','赵胜','刘文']
columns = ['语文','数学','英语']
df = pd.DataFrame(list,index,columns)
print('原始数据:\n',df)
print('选取所有学生的语文成绩:\n',df['语文'])
print('选取所有学生的语文和数学成绩:\n',df['语文','数学'])
print('选取王蒙到赵胜的语文和英语成绩:\n',df[['语文','英语']])
print('选取李珊及后面同学的所有成绩:\n',df[['语文','数学','英语']]['李珊':])